package com.welab.pandahelper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.welab.pandahelper.R;
import com.welab.pandahelper.bean.ExpandableListItem;

import java.util.List;


/**
 * Created by
 */
public class AppsListAdapter extends BaseAdapter {

    private Context mContext;
    private List<ExpandableListItem> mAppsData;


    public AppsListAdapter(Context context, List<ExpandableListItem> listChildData) {
        this.mContext = context;
        this.mAppsData = listChildData;
    }

    @Override
    public int getCount() {
        return mAppsData.size();
    }

    @Override
    public ExpandableListItem getItem(int position) {
        return mAppsData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ExpandableListItem childText = getItem(position);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        ImageView iconImage = (ImageView) convertView.findViewById(R.id.imageViewIcon);
        iconImage.setImageDrawable(childText.getIcon());

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(90, 90);
        iconImage.setLayoutParams(layoutParams);

        TextView txtListChild = (TextView) convertView.findViewById(R.id.txtListItem);
        txtListChild.setText(childText.getAppName());

        TextView txtListPkg = (TextView) convertView.findViewById(R.id.txtListPkg);
        txtListPkg.setText(childText.getPckName());
        convertView.findViewById(R.id.checked_imv).setVisibility(childText.isSelected() ? View.VISIBLE : View.INVISIBLE);
        return convertView;
    }
}